package Storage;

import Object.DSException;

//@author A0103535R
/************************************ Abstract Class DSSettingStore ***************************/
public class DSSettingStore {
	private static DSSettingStore _settingStore = null;
	
	private DSSettingFileHandler _settingFileHandler = null;
	private int _backgroundNum = 1;
	private boolean _isAnimated = true;

	/**
	 * This is the constructor of DSSettingStore.
	 * 
	 * @throws DSException
	 */
	private DSSettingStore() throws DSException {
		_settingFileHandler = DSSettingFileHandler.getInstance();
		_backgroundNum = _settingFileHandler.loadBackgroundNumFromSettingFile();
		_isAnimated = _settingFileHandler.loadIsAnimatedFromSettingFile();
	}

	/**
	 * This function is used to get the instance singleton of DSFileHandler.
	 * 
	 * @return the singleton instance of DSSettingStore.
	 * 
	 * @throws DSException
	 */
	public static DSSettingStore getInstance() throws DSException {
		if (_settingStore == null) {
			_settingStore = new DSSettingStore();
		}
		return _settingStore;
	}

	/**
	 * This function is used to get the background number stored.
	 * 
	 * @return the background number stored.
	 */
	public int getBackgroundNum() {
		return _backgroundNum;
	}

	/**
	 * This function is used to get the setting of animation stored.
	 * 
	 * @return the boolean value that represents the setting of animation.
	 */
	public boolean isAinimated() {
		return _isAnimated;
	}

	/**
	 * This function is used to store the updated background setting.
	 * 
	 * @throws DSException
	 */
	public void updateBackgroundNum(int bgn) throws DSException {
		_backgroundNum = bgn;
		_settingFileHandler.saveToSettingFile(_backgroundNum, _isAnimated);
	}

	/**
	 * This function is used to store the updated animation setting.
	 * 
	 * @throws DSException
	 */
	public void updateAnimation(boolean isAnimated) throws DSException {
		_isAnimated = isAnimated;
		_settingFileHandler.saveToSettingFile(_backgroundNum, _isAnimated);
	}
}
